
function changeButton(obj,image)
{
	
obj.style.backgroundImage = image;

	}
	// JavaScript Document

function changeimage()
{
document.getElementById("safecode").src='admin_core/utils/validate_code.php?time'+Math.random();
}

function submitForm()
{
	
	var form = document.getElementById("registForm");
	var loginName = document.getElementById("loginName").value;
	var pwd = document.getElementById("pwd").value;
	var pwdAgain = document.getElementById("pwdAgain").value;
	var rname = document.getElementById("rname").value;
	var email = document.getElementById("email").value;
	var tele = document.getElementById("tele").value;
	var validata = document.getElementById("validata").value;
	var upload = document.getElementById('upload').value;
	var namestate = document.getElementById('namestate').value;
	var xy =document.getElementById('xy').value;
	if(loginName.length<6)
	{
		alert("用户名必须大于等于六位！");
		document.getElementById("loginName").focus();
		addBackGround(document.getElementById("loginName"));
		}
		else if(namestate == 0)
	{
		alert("该用户名已被注册！请重新学则用户名！");
		document.getElementById("loginName").focus();
		addBackGround(document.getElementById("loginName"));
		}
		else if(pwd.length<6)
		{
			alert("密码必须大于等于六位！");
			document.getElementById("pwd").focus();
			addBackGround(document.getElementById("pwd"));
			}
			else if(pwd != pwdAgain)
			{
				alert("密码不一致！");
				document.getElementById("pwdAgain").focus();
				addBackGround(document.getElementById("pwdAgain"));
				}
			else if(rname==null||rname=="")
			{
				alert("真实姓名不能为空！");
				document.getElementById("rname").focus();
				addBackGround(document.getElementById("rname"));
				}
				else if(!checkEmail(email))
				{
					alert("邮箱不符合规格！");
					document.getElementById("email").focus();
					addBackGround(document.getElementById("email"));
					}
					else if(!checkTele(tele)||tele.length<11||tele.length>11)
					{
						alert("电话格式不正确！");
						document.getElementById("tele").focus();
						addBackGround(document.getElementById("tele"));
					}
					else if(xy == "none")
							{
								alert("请选择学院！");
								}
					else if(document.getElementById('zhy')!=null)
								{
									if(document.getElementById('zhy').value=="none")
									{
										alert("请选择专业！");
										}
									else if(document.getElementById('bj')!=null)
									{
										if(document.getElementById('bj').value=="none")
										{
											alert("请选择班级！");
										
											}
										else if(document.getElementById("xh")!=null)
										{
										var xh = document.getElementById("xh").value;
											if(!checkTele(xh)||xh.length>2)
										{
											alert("学号格式不正确！");
											document.getElementById("xh").focus();
											addBackGround(document.getElementById("xh"));
											}
											else if(upload == ""&&document.getElementById("loginName").value!="none111")
											{
									
												alert("请选择你的头像！");
												}
											else if(validata==""){
												alert("验证码不能为空！");
												}
												else {
												form.submit();}
											}
									
										}
									}
					else 
						{
							 if(upload == ""&&document.getElementById("loginName").value!="none111")
											{
												alert("请选择你的头像！");
												}
						 else if(validata==""){
							alert("验证码不能为空！");
							}
							else {
							form.submit();}
						
						}
									
					
						
					

	}
function addBackGround(obj)
{
	obj.style.background="#CCC";
	}
	function removeBackGround(obj)
	{
		obj.style.background ="#FFF";
		}
		function alertMessage(obj)
		{
			var parent = obj.parentNode;
			var span = document.createElement('span')
			var name = obj.name;
			var regist = document.getElementById("regist");
			if(document.getElementById("mes"+name)==null)
			{
				
				if(name == "loginName")
				{
					appendMessage("icon_alert.gif",parent,span,"用户名必须大于六位！",name);
					
					}
					else if(name == "pwd")
					{
						appendMessage("icon_alert.gif",parent,span,"密码必须大于六位！",name);
						}
						else if(name == "pwdAgain")
						{
								appendMessage("icon_alert.gif",parent,span,"密码必须与上面的一致！",name);
							}
							else if(name == "rname")
							{
								appendMessage("icon_alert.gif",parent,span,"必须是你身份证上姓名！",name);
								}
								else if(name == "email")
								{
									appendMessage("icon_alert.gif",parent,span,"必须是有效的邮箱格式！",name);
									}
								else if(name == "tele")
								{
									appendMessage("icon_alert.gif",parent,span,"必须是你近期用的号码！",name);
									}
									else if(name == "xh")
									{
										appendMessage("icon_alert.gif",parent,span,"是你在本班的学号，如31号！",name);
										}
				}
			}
			function checkValue(obj)
			{
				var name = obj.name;
				var value = obj.value;
				var state = false;
				if(document.getElementById("mes"+name)!=null)
				{
					var span = document.getElementById("mes"+name);
					if(name == "loginName")
				{
					if(value.length<6)
					{
						span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;用户名必须大于六位！";
					
						state  = false;
						}
						else
						{
							if(document.getElementById('zhy')==null&&document.getElementById('checktype')==null)
							{
							checkTeacherName(obj);
							}
							else
							{
								checkStudentName(obj);
								}
							}
					}
					else if(name == "pwd")
					{
						if(value.length<6)
					{
						span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;密码必须大于六位！";
						state = false;
						}
						else
						{
							span.innerHTML="<img src='images/icon_accept.gif' width='12' height='12'></img>&nbsp;密码可用！";
							state = true;
							}
						}
						else if(name == "pwdAgain")
						{
								var pwd = document.getElementById("pwd").value;
								if(pwd==value)
								{
									span.innerHTML="<img src='images/icon_accept.gif' width='12' height='12'></img>&nbsp;密码一致！";
									state = false;
									
									}
									else
									{
										span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;密码不一致！";
										state = false;
										}
							}
							else if(name == "rname")
							{
								obj.parentNode.removeChild(span);
								}
								else if(name == "email")
								{
									if(checkEmail(value))
									{
											span.innerHTML="<img src='images/icon_accept.gif' width='12' height='12'></img>&nbsp;邮箱格式正确！";
											state = true;
										}
										else 
								{
									span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;邮箱格式不正确！";
									state = false;
									}
									}
								else if(name == "tele")
								{
									
									if(checkTele(value))
									{
										if( value.length==11)
									{	span.innerHTML="<img src='images/icon_accept.gif' width='12' height='12'></img>&nbsp;号码格式正确!";
									state =true;
									}
										else 
		{								span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;号码格式不正确!";
										state =false;
										}
										}
										else
										{
											span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;号码格式不正确!";
											state =false;
											}
									}
									else if(name == "xh")
									{
										if(checkTele(value))
										{
											if(value.length<=2)
										{	
										checkXH(obj);
										state =true;
										}
							else
								{			span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;学号格式不正确!";
											state =false;
											
											}
											}
											else
											{
												span.innerHTML="<img src='images/action_stop.gif' width='12' height='12'></img>&nbsp;学号格式不正确!";
												state =false;
												}
										}
										
											
										
					
					
					}
				}
		function checkEmail(email)
	{
		if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		{
			return true;
			}
			else
			{
				return false;
				}
		}
		function checkTele(tele)
		{
			if(tele.search(/[0-9]/)!=-1)
			{
				return true;}
				else
				{
					return false;}
			}
		function appendMessage(image,parentNode,span,text,name)
	{
		    span.innerHTML ="<img src='images/"+image+"' width='12' height='12'></img>&nbsp;";
	        span.appendChild(document.createTextNode(text));
			span.style.border = "solid 1px red";
			span.style.backgroundColor = "#CCC";
			span.style.color = "red";
			span.style.width = "30px";
			span.style.fontSize = "12px";
			span.style.marginLeft = "5px";
			span.id ="mes"+name;
	        parentNode.appendChild(span);
		}